-- career
-- create by cheny3
-- 学习称号

return {
    -- 判断
    canTrigger = function(args)
        -- 判断有没有可以学习的称号
        if CareerM.checkCareer() then
            return true;
        end
        return false;
    end,

    -- 触发
    trigger = function(args)
        -- 获取称号信息
        local careers = table.keys(CareerM.getTable());
        local pet = ME.user:getActivePet();

        -- 把称号ID打乱顺序/两两交换
        for oriIndex, id in pairs(careers) do
            local toIndex = math.random(#careers);
            local temp = careers[toIndex];
            careers[toIndex] = careers[oriIndex];
            careers[oriIndex] = temp;
        end

        for _, careerId in pairs(careers) do
            if CareerM.canJoin(pet.classId, careerId) == true then
                return DungeonActionM.go("join_career", pet.classId, careerId);
            else
                for feature = 1, 4 do
                    local info = CareerM.getCareerInfo(careerId, "feature" .. feature);
                    if type(info) == "table" and #table.keys(info) > 0
                        and CareerM.canUpgrade(pet.classId, careerId, feature) == true then
                        return DungeonActionM.go("upgrade_career", careerId, feature);
                    end
                end
            end
        end

        return false;
    end,
};
